
unit clsMovto_NaoConf;

interface

uses dbtables,dm;

type TMovto_NaoConf = class(TObject)
     public
      QtdeProd_Ncf   : double;
      procedure Gravar(Num_Planilha: string; P_lancamento_imq: int64; P_cod_ncf: string);
      function  Recuperar(Num_Planilha: string; P_lancamento_imq: int64; var P_cod_ncf: string): boolean;
      procedure Excluir(Num_Planilha: string);
     end;

implementation

procedure TMovto_NaoConf.Excluir;
var tq: TQuery;
begin
 tq             := TQuery.create(DmInt);
 tq.DatabaseName:= DmInt.Db.DatabaseName;
 tq.Active      := false;
 tq.sql.clear;
 tq.Params.clear;
 tq.sql.add('Delete from Movto_NaoConf where Num_Planilha=:a');
 tq.params[0].AsString:= Num_Planilha;
 tq.ExecSQL;
 tq.close;
 tq.free;
end;

procedure TMovto_NaoConf.Gravar;
var tq: TQuery;
begin
 tq             := TQuery.create(DmInt);
 tq.DatabaseName:= DmInt.Db.DatabaseName;
 tq.Active      := false;
 tq.sql.clear;
 tq.Params.clear;
 tq.sql.add('Select * from movto_naoconf where Num_Planilha=:a and lancamento_imq=:b and '+
            'cod_ncf=:c');
 tq.params[0].AsString := Num_Planilha;
 tq.params[1].AsInteger:= P_lancamento_imq;
 tq.params[2].AsString := P_cod_ncf;
 tq.open;
 if tq.eof then begin
  tq.Close;
  tq.sql.clear;
  tq.Params.clear;
  tq.sql.add('Insert into Movto_naoconf values(:k_Num_Planilha,:K_lancamento_imq,'+
             ':K_cod_ncf,:K_QtdeProd_ncf)');
 end else begin
  tq.Close;
  tq.sql.clear;
  tq.Params.clear;
  tq.sql.add('Update Movto_naoconf set QtdeProd_ncf=:K_QtdeProd_ncf where '+
             'Num_Planilha=:k_Num_Planilha and lancamento_imq=:K_lancamento_imq and '+
             'cod_ncf=:K_cod_ncf');
 end;
 tq.ParamByName('k_Num_Planilha').AsString    := Num_Planilha;
 tq.ParamByName('K_lancamento_imq').AsInteger := P_lancamento_imq;
 tq.ParamByName('K_cod_ncf').AsString         := P_cod_ncf;
 tq.ParamByName('K_QtdeProd_ncf').AsFloat     := QtdeProd_Ncf;
 tq.ExecSQL;
 tq.close;
 tq.free;
end;

function TMovto_NaoConf.Recuperar;
var tq: TQuery;
begin
 tq             := TQuery.create(DmInt);
 tq.DatabaseName:= DmInt.Db.DatabaseName;
 tq.Active      := false;
 tq.sql.clear;
 tq.Params.clear;
 tq.sql.add('Select * from movto_naoconf where Num_Planilha=:a and lancamento_imq=:b');
 tq.params[0].AsString := Num_Planilha;
 tq.params[1].AsInteger:= P_lancamento_imq;
 tq.open;
 if not tq.eof then result:= true else result:= false;
 P_cod_ncf   := tq.fieldbyname('cod_ncf').asstring;
 QtdeProd_Ncf:= tq.fieldbyname('QtdeProd_Ncf').AsFloat;
 tq.close;
 tq.free;
end;

end.
